home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / main / menuseg.c < prev    next >
Text File  |  1994-04-15  |  37KB  |  1,350 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************
  13. *
  14. *    Menu Handling and initialization code.
  15. *
  16. *    
  17. *    Revisions:
  18. *    7/92 Telnet 2.6 initial version: reorganized defines, put all stray globals in a struct, and
  19. *                put all cursors in a nice array.  Moved some routines to other places -    Scott Bulmahn            
  20. *
  21. */
  22.  
  23. #ifdef MPW
  24. #pragma segment 4
  25. #endif
  26.  
  27. #include    <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. #include "TelnetHeader.h"
  32. #include    "wind.h"
  33. #include "menuseg.proto.h"
  34. #include "mainseg.proto.h"
  35. #include "Sets.proto.h"                /* JMB: For Saved Sets functions */
  36. #include    "configure.proto.h"
  37. #include "parse.proto.h"
  38. #include "InternalEvents.h"
  39. #include "mydnr.proto.h"
  40. #include "rsmac.proto.h"
  41. #include "network.proto.h"
  42. #include "maclook.proto.h"
  43. #include "vrrgmac.proto.h"
  44. #include "rgmp.proto.h"
  45. #include "tekrgmac.proto.h"
  46. #include "vgtek.proto.h"
  47. #include "netevent.proto.h"
  48. #include "Connections.proto.h"
  49.  
  50. #include "vsdata.h"
  51. #include "vsinterf.proto.h"
  52.  
  53. #include "event.proto.h"
  54. #include "macros.proto.h"
  55. #include "DlogUtils.proto.h"            /* For VersionNumber, OutlineItem, and DialogProc Protos */
  56. #include "telneterrors.h"
  57. #include "debug.h"
  58.  
  59. #include <Printing.h>
  60. #include "printing.proto.h"
  61. #include "menuseg.proto.h"
  62. #include "translate.proto.h"
  63. #include "parse.proto.h"                // For SendNAWSinfo proto
  64.  
  65. MenuHandle
  66.     myMenus[NMENUS];        /* Menu Handles .... */
  67.  
  68. char *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  69.  
  70.  
  71. /*
  72.  * External variable declarations (those which we borrow )
  73.  *
  74.  */
  75. extern short scrn;
  76. extern Cursor *theCursors[];
  77. extern WindRec
  78.     *screens,            /* The screen array from Maclook */
  79.     *ftplog;                    /* The FTP log screen from Maclook */
  80. extern SysEnvRec theWorld;                        /* System Environment record */
  81. extern    short    nNational;
  82.  
  83. void CloseCaptureFile(short w)
  84. {
  85.     VSclosecapture(w);                                /* BYU 2.4.18 */
  86.     CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  87. }
  88.  
  89. /*    portsOpen()    - Count the number of ports open. Returns 3 different answers
  90.  *                  0= no ports at all, 1= at least active, -1= ports/none active. */
  91. short    portsOpen(void)
  92. {
  93.     short pnum;
  94.  
  95.     pnum=TelInfo->numwindows-1;
  96.     if (pnum<0)  return(0);
  97.     while (pnum>=0) 
  98. //        if (!screens[pnum--].active && !screens[pnum+1].corpse) return(1);
  99.         // corpse status now part of active flag
  100.         if (screens[pnum--].active == CNXN_ACTIVE) return(1);
  101.     return(-1);
  102. }
  103.  
  104. void    AdjustMenus(void)
  105. {
  106.     short        i;
  107.     WindowPtr    wind;
  108.     
  109.     if ((wind = FrontWindow()) != NULL && (((WindowPeek)wind)->windowKind >= userKind))
  110.         EnableItem( myMenus[Fil],FLclose);
  111.     else
  112.         DisableItem( myMenus[Fil],FLclose);
  113.         
  114.     if ((i=portsOpen()) <1) {
  115.         DisableItem( myMenus[Fil],FLsave);
  116.         DisableItem( myMenus[Fil],FLprint);
  117.         DisableItem( myMenus[Edit],EDcut);
  118.         DisableItem( myMenus[Edit],EDundo);
  119.         DisableItem( myMenus[Edit],EDclear);
  120.         DisableItem( myMenus[Edit],EDcopy);
  121.         DisableItem( myMenus[Edit],EDcopyt);
  122.  
  123.  
  124.         DisableItem( myMenus[Emul],EMbs);
  125.         DisableItem( myMenus[Emul],EMdel);
  126.         DisableItem( myMenus[Emul],EMecho);
  127.         DisableItem( myMenus[Emul],EMwrap);
  128.         DisableItem( myMenus[Emul],EMscroll);
  129.         DisableItem( myMenus[Emul],EMreset);
  130.         DisableItem ( myMenus[Emul],EMjump);
  131.         DisableItem ( myMenus[Emul],EMpage);
  132.         DisableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  133.         DisableItem ( myMenus[Emul],EMscreensize);
  134.         DisableItem ( myMenus[Emul],EMsetup);
  135.         DisableItem ( myMenus[Emul],EMfont);
  136.         DisableItem ( myMenus[Emul],EMsize);
  137.         DisableItem ( myMenus[Emul],EMcolor);
  138.         DisableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  139.  
  140.         DisableItem( myMenus[Net ],NEftp);
  141.         DisableItem( myMenus[Net ],NEip);
  142.         DisableItem( myMenus[Net ],NEayt);
  143.         DisableItem( myMenus[Net ],NEao);
  144.         DisableItem( myMenus[Net ],NEinter);
  145.         DisableItem( myMenus[Net ],NEec);
  146.         DisableItem( myMenus[Net ],NEel);
  147.         DisableItem( myMenus[Net ],NEscroll);
  148.  
  149.         if (TelInfo->ScrlLock) {
  150.             TelInfo->ScrlLock=0;
  151.             CheckItem(myMenus[Net ], NEscroll,FALSE);
  152.             }
  153.         }
  154.     else {
  155.         EnableItem ( myMenus[Fil],FLsave);
  156.  
  157. /*        EnableItem ( myMenus[Fil],FLprint); */
  158.  
  159.         EnableItem ( myMenus[Emul],EMbs);
  160.         EnableItem ( myMenus[Emul],EMdel);
  161.         EnableItem ( myMenus[Emul],EMecho);
  162.         EnableItem ( myMenus[Emul],EMwrap);
  163.         if (nNational > 0) {
  164.             EnableItem ( myMenus[National], 0);
  165.             }
  166.         EnableItem ( myMenus[Emul],EMscroll);
  167.         EnableItem ( myMenus[Emul],EMreset);
  168.         EnableItem ( myMenus[Emul],EMjump);
  169.         EnableItem ( myMenus[Emul],EMpage);
  170.         EnableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  171.         EnableItem ( myMenus[Emul],EMscreensize);
  172.         EnableItem ( myMenus[Emul],EMsetup);
  173.         EnableItem ( myMenus[Emul],EMfont);
  174.         EnableItem ( myMenus[Emul],EMsize);
  175.         EnableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  176.     
  177.         if (theWorld.hasColorQD) 
  178.             EnableItem ( myMenus[Emul],EMcolor);
  179.  
  180.         EnableItem ( myMenus[Net ],NEftp);
  181.         EnableItem ( myMenus[Net ],NEip);
  182.         EnableItem ( myMenus[Net ],NEayt);
  183.         EnableItem ( myMenus[Net ],NEao);
  184.         EnableItem ( myMenus[Net ],NEinter);
  185.         EnableItem ( myMenus[Net ],NEec);
  186.         EnableItem ( myMenus[Net ],NEel);
  187.         EnableItem ( myMenus[Net ],NEscroll);
  188.     }
  189.  
  190. }
  191.  
  192. /*    switchMenus( which) - Switch from our current menus to the key menus (1)
  193.  *                          or the normal menus (0). */
  194. void switchMenus(short which)
  195. {
  196.     short i;
  197.  
  198.     DeleteMenu( fileMenu);                    /* Take them from the menu bar */
  199.     DeleteMenu( editMenu);
  200.     DeleteMenu( termMenu);
  201.     DeleteMenu(  netMenu);
  202.     DeleteMenu(NfileMenu);                    /* Take them from the menu bar */
  203.     DeleteMenu(NeditMenu);
  204.     DeleteMenu(NtermMenu);
  205.     DeleteMenu(NnetMenu);
  206.  
  207.     if (which) {
  208.         myMenus[Fil ] = GetMenu(NfileMenu);
  209.         myMenus[Edit] = GetMenu(NeditMenu);
  210.         myMenus[Emul] = GetMenu(NtermMenu);
  211.         myMenus[Net ] = GetMenu(NnetMenu );
  212.         DelMenuItem(myMenus[Conn],COnext);
  213.         InsMenuItem(myMenus[Conn],(StringPtr)"\017Next Session/N\0",0);
  214.         }
  215.     else {
  216.         myMenus[Fil ] = GetMenu(fileMenu);
  217.         myMenus[Edit] = GetMenu(editMenu);
  218.         myMenus[Emul] = GetMenu(termMenu);
  219.         myMenus[Net ] = GetMenu( netMenu);
  220.         DelMenuItem(myMenus[Conn],COnext);
  221.         InsMenuItem(myMenus[Conn],(StringPtr)"\015Next Session\0",0);
  222.         }
  223.  
  224.     for(i=1; i<Conn; i++)
  225.         InsertMenu( myMenus[i], connMenu);    /* Put them in the menu bar */
  226.  
  227.     AdjustMenus();            /* Hilite the right stuff */
  228.  
  229.     if (TelInfo->MacBinary)
  230.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  231.     else
  232.         CheckItem(myMenus[Fil],FLbin,FALSE);
  233.  
  234.     if (TelInfo->ftplogon)
  235.         CheckItem(myMenus[Fil],FLlog,TRUE);        /* and the log .... */
  236.     else
  237.         CheckItem(myMenus[Fil],FLlog,FALSE);
  238.  
  239.     if (TelInfo->ScrlLock)                                 /* and the Suspend network ... */
  240.         CheckItem(myMenus[Net], NEscroll,TRUE);
  241.     else 
  242.         CheckItem(myMenus[Net], NEscroll,FALSE);
  243.  
  244.     if (TelInfo->numwindows>0)                            /* and set the BSDEL flag */
  245.         CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  246.  
  247.     DrawMenuBar();                                /* Draw what we have done */
  248.  
  249.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  250.  
  251.     if (!theWorld.hasColorQD)
  252.         DisableItem( myMenus[Emul], EMcolor);
  253. }
  254.  
  255. /*    setupmenu - Set up (load) all menus and prepare menu bar.
  256.  *                set default check marks. */
  257. void setupmenu(short def)
  258. {
  259.     myMenus[0] = GetMenu(appleMenu);                /* Get all of our friendly menus */
  260.     myMenus[Conn] = GetMenu(connMenu);
  261.     myMenus[Font] = GetMenu(fontMenu);
  262.     myMenus[Sizem] = GetMenu(sizeMenu);
  263.     myMenus[OpSpec] = GetMenu(opspecMenu);
  264.     myMenus[PrefsSub] = GetMenu(prefsMenu);
  265.     myMenus[National] = GetMenu(transMenu);
  266.  
  267.     AddResMenu(myMenus[0], 'DRVR');                    /* Add in the DA's */
  268.  
  269.     InsertMenu(myMenus[0], 0);                        /* Insert the Menus into the bar */
  270.     InsertMenu(myMenus[Conn], 0);
  271.     InsertMenu(myMenus[Font], -1);
  272.     InsertMenu(myMenus[Sizem], -1);
  273.     InsertMenu(myMenus[OpSpec], -1);
  274.     InsertMenu(myMenus[National], -1);
  275.     InsertMenu(myMenus[PrefsSub], -1);
  276.  
  277.     AddResMenu(myMenus[Font], 'FONT');                /* Put the fonts in the font menu */
  278.  
  279.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  280.     switchMenus(def);
  281. }
  282.  
  283. void CheckOpSpecSubmenu(void)
  284. {
  285.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  286. }
  287.  
  288. void SetupOpSpecSubmenu(MenuHandle theMenu)
  289. {
  290.     short            scratchshort;
  291.         
  292.     scratchshort = CountMItems(theMenu);
  293.     for (; scratchshort>0; scratchshort--) DelMenuItem(theMenu, scratchshort);
  294.  
  295.     UseResFile(TelInfo->SettingsFile);
  296.     AddResMenu(theMenu, SESSIONPREFS_RESTYPE);
  297. }
  298.  
  299. /*    updateMenuChecks() - update the check marks for file transfer
  300.  *                         (MacBinary) */
  301.  
  302. void updateMenuChecks( void)
  303. {
  304.     if (TelInfo->MacBinary)
  305.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  306.     else
  307.         CheckItem(myMenus[Fil],FLbin,FALSE);
  308. }
  309.  
  310. /*    DisplayMacBinary()    - Sets the macbinary check mark according to the MacBinary flag */
  311. void DisplayMacBinary( void)
  312. {
  313.     if (TelInfo->MacBinary)
  314.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  315.     else
  316.         CheckItem(myMenus[Fil],FLbin,FALSE);
  317. }
  318.  
  319. /*CheckFonts()        - Place checkmarks and outlines on the appropriate
  320.  *                          menu items for the fonts */
  321. void CheckFonts(void)
  322. {
  323.     short     i, fsiz, fnum;
  324.     long    itemFontSize;
  325.     Str255     temp, itemString;
  326.  
  327.     RSgetfont( screens[scrn].vs, &fnum, &fsiz);
  328.     GetFontName(fnum, temp);
  329.     
  330.     for(i=1; i<= CountMItems( myMenus[Font]); i++)
  331.         {
  332.         GetItem( myMenus[Font], i, itemString);
  333.         if (EqualString(temp, itemString, FALSE, FALSE))
  334.             CheckItem( myMenus[Font], i, TRUE);            /* Check the current font */
  335.         else
  336.             CheckItem( myMenus[Font], i, FALSE);
  337.         }
  338.     
  339.     for(i=1; i<=CountMItems( myMenus[Sizem]); i++) {
  340.         GetItem( myMenus[Sizem], i, itemString);            /* JMB 2.6 -- Much safer to do it */
  341.         StringToNum(itemString, &itemFontSize);            /*                this way! */
  342.  
  343.         if (fsiz == (short)itemFontSize)
  344.             CheckItem( myMenus[Sizem], i, TRUE);            /* Check Our Current Size */
  345.         else
  346.             CheckItem( myMenus[Sizem], i, FALSE);
  347.  
  348.         if (RealFont( fnum, (short)itemFontSize))        /* Outline All Available REAL Sizes */
  349.             SetItemStyle( myMenus[Sizem], i, outline);
  350.         else
  351.             SetItemStyle( myMenus[Sizem], i, 0);
  352.         }
  353. }
  354.  
  355. /*    applAbout - display the about dialog for the application.*/
  356. void applAbout( void)
  357. {
  358.     DialogPtr About;
  359.     short itemhit;
  360.  
  361.     About=GetNewMyDialog( AboutDLOG, (Ptr) 0L,(WindowPtr) -1L, (void *)ThirdCenterDialog);
  362.     if (About) {
  363.         UItemAssign( About, 2, VersionNumberUPP);
  364.         ModalDialog(NULL, &itemhit);
  365.         DisposDialog(About);
  366.         }
  367. }
  368.  
  369. short ReallyClose( short scrn)
  370. {
  371.     DialogPtr    dtemp;
  372.     short        item;
  373.     Str255        scratchPstring;
  374.     
  375.     SetCursor(theCursors[normcurs]);
  376.  
  377.     GetWTitle(screens[scrn].wind, scratchPstring);
  378.     ParamText(scratchPstring, NULL, NULL, NULL);
  379.     
  380.     dtemp = GetNewMyDialog( CloseDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  381.  
  382.     item = DLOGCancel +1;
  383.     while (item> DLOGCancel)
  384.         ModalDialog(DLOGwOK_CancelUPP, &item);
  385.  
  386.     DisposDialog( dtemp);
  387.  
  388.     updateCursor(1);
  389.     
  390.     if (item == DLOGCancel) return(0);
  391.  
  392.     return(1);
  393. }
  394.  
  395. PicHandle RGtoPICT(short i)
  396. {
  397.     short j;
  398.     PicHandle tpic;
  399.     Rect trect;
  400.  
  401.     SetRect(&trect,0,0,384,384);
  402.     j=VGnewwin(3,VGgetVS(i));            /* NCSA 2.5: get the right VS */
  403.     RGMPsize( &trect );
  404.     VGzcpy( i, j);                /* Love dat zm factr */
  405.     tpic=OpenPicture(&trect);
  406.     ClipRect(&trect);
  407.     
  408.     VGredraw(i,j);
  409.     ClosePicture();
  410.     VGclose(j);
  411.  
  412.     return(tpic);
  413. }
  414.  
  415. /* 
  416.  * copyGraph    - Copy the current graphics screen.
  417.  *            dnum - the number of the drawing to copy .
  418.  */
  419. void copyGraph( short dnum)
  420. {
  421.     long tlong;                    /* Temporary Variable */
  422.     PicHandle tpic;                /* Mental picture of the thing */
  423.  
  424.     tpic=RGtoPICT(dnum);            /* Get the picture */
  425.     tlong=ZeroScrap();                /* Nobody else can live here */
  426.     HLock((Handle) tpic);                    /* Lock it for Puting */
  427.     tlong=PutScrap(GetHandleSize((Handle) tpic),'PICT', (Ptr) *tpic);    /* Store as a PICT */
  428.     HUnlock((Handle) tpic);                    /* Unlock so we can toss it */
  429.     KillPicture(tpic);                /* Kill the picture..... */
  430. }                
  431.  
  432. /* 
  433.  * copyText    - Copy the current selection on the virtual screen
  434.  *            vs - the number of the virtual screen to copy from
  435.  */
  436.  
  437. void copyText( short vs)
  438. {
  439.     char **charh;            /* where to store the characters */
  440.     long tlong;                /* Necessary temporary variable */
  441.  
  442.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  443.  
  444.     charh=RSGetTextSel(vs,0);        /* Get the text selection */
  445.  
  446.     if (charh == (char **)-1L)
  447.         OutOfMemory(400);
  448.     else if (charh != (char **)0L) {    /* BYU LSC - Can't do anything without characters */
  449.         HLock(charh);                /* Lock for putting */
  450.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  451.                                     /* Put it as a TEXT resource */
  452.         HUnlock(charh);                /* Unlock for disposal */
  453.         DisposHandle(charh);        /* Kill the chars */
  454.         }
  455. }
  456.  
  457. /* 
  458.  * copyTable   - Copy the current selection on the virtual screen
  459.  *            vs - the number of the virtual screen to copy from
  460.  */
  461.  
  462. void copyTable( short vs)
  463. {
  464.     char **charh;            /* where to store the characters */
  465.     long tlong;                /* Necessary temporary variable */
  466.  
  467.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  468.  
  469.     charh=RSGetTextSel(vs, gApplicationPrefs->CopyTableThresh);        /* Get the text selection */
  470.  
  471.     if (charh>(char **)0L) {                    /* BYU LSC - Can't do anything without characters */
  472.         HLock(charh);                /* Lock for putting */
  473.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  474.                                     /* Put it as a TEXT resource */
  475.         HUnlock(charh);                /* Unlock for disposal */
  476.         DisposHandle(charh);        /* Kill the chars */
  477.         }
  478.     else putln("No characters to copy darn it!");
  479. }
  480.  
  481. /*
  482.  *    paste - Paste the resource from the scrap into the current WIND, if
  483.  *            and only if it is really text
  484.  */
  485.  
  486. void paste( void)
  487. {
  488.     long
  489.         off,                /* offset */
  490.         length;                /* the lenght of what is on the Scrap */
  491.  
  492.     if (screens[scrn].clientflags & PASTE_IN_PROGRESS) {  // One paste at a time, please
  493.         SysBeep(4);
  494.         return;
  495.         }
  496.         
  497.     /* Flush the buffer if we have echo */
  498.     if ((screens[scrn].ftpstate == 0) &&    /* BYU */
  499.         screens[scrn].echo &&                 /* BYU */
  500.         screens[scrn].kblen>0) {            /* BYU */
  501.         netwrite( screens[scrn].port, screens[scrn].kbbuf,
  502.                     screens[scrn].kblen);    /* if full send buffer */
  503.         screens[scrn].kblen=0;
  504.         }
  505.  
  506.     if (GetScrap(0L, 'TEXT', &off)<=0L)        /* If there are no TEXT res's */
  507.             return;                        /* then we can't paste it */
  508.  
  509.     screens[scrn].outhand=NewHandle(0L);    /* create a handle to put chars in */
  510.  
  511.     length= GetScrap( screens[scrn].outhand, 'TEXT',&off);
  512.                                             /* Store the scrap into the handle */
  513.     screens[scrn].outlen = length;            /* Set the length */
  514.     HLock(screens[scrn].outhand);            /* Lock the Handle down for safety */
  515.     screens[scrn].outptr=*screens[scrn].outhand;    /* Set the pointer */
  516.  
  517.     screens[scrn].clientflags |= PASTE_IN_PROGRESS;
  518.     screens[scrn].incount = 0;
  519.     screens[scrn].outcount = 0;
  520.     
  521.     trbuf_mac_nat((unsigned char *)screens[scrn].outptr,screens[scrn].outlen, screens[scrn].national);    /* LU: translate to national chars */
  522.  
  523.     pasteText( scrn);    /* BYU LSC - routine to paste to net, w/echo if neccessary */
  524. }
  525.  
  526. void displayStatus(short n)
  527. {
  528.     DialogPtr        dptr;
  529.     short            item;
  530.     Str255            scratchPstring;
  531.     
  532.     SetCursor(theCursors[normcurs]);
  533.     
  534.     switch(screens[n].active) {
  535.         case CNXN_ISCORPSE:
  536.             GetWTitle(screens[n].wind, scratchPstring);
  537.             ParamText( scratchPstring, "\pawaiting dismissal", NULL, NULL);
  538.             break;
  539.         case CNXN_OPENING:
  540.             ParamText( screens[n].machine,"\pbeing opened", NULL, NULL);
  541.             break;
  542.         default:
  543.             ParamText( screens[n].machine,"\pbeing looked up", NULL, NULL);
  544.         }
  545.  
  546.     dptr = GetNewMyDialog( StatusDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  547.  
  548.     item = DLOGCancel+1;
  549.     while (item > DLOGCancel)
  550.         ModalDialog(DLOGwOK_CancelUPP, &item);
  551.  
  552.     updateCursor(1);
  553.     
  554.     if (item == DLOGCancel) {
  555.         netclose(screens[n].port);
  556.         destroyport( n);
  557.         }    
  558.  
  559.     DisposDialog(dptr);
  560. }
  561.  
  562. /*
  563.  *    changeport - handle the menu updates for changing from one port to another
  564.  */
  565. void changeport(short oldprt, short newprt)
  566. {
  567.  
  568.     sprintf(tempspot,"oldscrn: %d, newscrn: %d",oldprt,newprt); putln(tempspot);
  569.     
  570.     if (screens[oldprt].active == CNXN_ACTIVE) 
  571.         CheckItem(myMenus[Conn], oldprt + FIRST_CNXN_ITEM, FALSE);        /* Adjust Conn menu */
  572.     CheckItem(myMenus[Conn], newprt + FIRST_CNXN_ITEM, TRUE);
  573.  
  574.     CheckItem(myMenus[Emul], EMbs,FALSE);                        /* Adjust BS */
  575.     CheckItem(myMenus[Emul], EMdel,FALSE);
  576.     CheckItem(myMenus[Emul], EMbs+screens[newprt].bsdel,TRUE);    /* and DEL */
  577.  
  578.     if (screens[newprt].tektype < 0) {    // TEK is inhibited
  579.         DisableItem(myMenus[Emul],EMclear);
  580.         DisableItem(myMenus[Emul],EMpage);
  581.         }
  582.     else {
  583.         EnableItem(myMenus[Emul],EMclear);
  584.         EnableItem(myMenus[Emul],EMpage);
  585.     
  586.         if (screens[newprt].tekclear)                /* BYU 2.4.8 */
  587.             CheckItem(myMenus[Emul],EMclear,TRUE);    /* BYU 2.4.8 */
  588.         else                                         /* BYU 2.4.8 */
  589.             CheckItem(myMenus[Emul],EMclear,FALSE);    /* BYU 2.4.8 */
  590.         }
  591.         
  592.     if (screens[newprt].ESscroll)
  593.         CheckItem(myMenus[Emul],EMscroll,TRUE);
  594.     else 
  595.         CheckItem(myMenus[Emul],EMscroll,FALSE);
  596.  
  597.     if (screens[newprt].echo)                     /* LOCAL ECHO */
  598.         CheckItem(myMenus[Emul],EMecho,TRUE);
  599.     else                                         /* REMOTE ECHO */
  600.         CheckItem(myMenus[Emul],EMecho,FALSE);
  601.         
  602.     if (screens[newprt].wrap)                     /* wrap on */
  603.         CheckItem(myMenus[Emul],EMwrap,TRUE);
  604.     else                                         /* wrap off */
  605.         CheckItem(myMenus[Emul],EMwrap,FALSE);
  606.  
  607.     if (VSiscapturing(screens[newprt].vs))                /* BYU 2.4.18 */
  608.         CheckItem(myMenus[Emul], EMcapture,TRUE);        /* BYU 2.4.18 */
  609.     else                                                /* BYU 2.4.18 */
  610.         CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  611.  
  612.     if (screens[newprt].arrowmap)                        /* JMB */
  613.         CheckItem(myMenus[Emul],EMarrowmap, TRUE);        /* JMB */
  614.     else                                                /* JMB */
  615.         CheckItem(myMenus[Emul],EMarrowmap, FALSE);        /* JMB */
  616.         
  617.     if (screens[newprt].pgupdwn)                        /* JMB */
  618.         CheckItem(myMenus[Emul],EMpgupdwn, TRUE);        /* JMB */
  619.     else                                                /* JMB */
  620.         CheckItem(myMenus[Emul],EMpgupdwn, FALSE);        /* JMB */
  621.     
  622.     scrn=newprt;
  623.  
  624.     CheckFonts();
  625.  
  626.     CheckNational(screens[newprt].national);
  627. }
  628.  
  629. // Returns TRUE if the user cancelled the quit
  630. Boolean    HandleQuit(void)
  631. {
  632.     short    i;
  633.     
  634.     if (TelInfo->numwindows>0) {
  635.         if (AskUserAlert(REALLY_QUIT_QUESTION, FALSE)) {
  636.             for (i = TelInfo->numwindows - 1; i >= 0; i--) {
  637.                 netclose(screens[i].port);
  638.                 destroyport(i);
  639.                 }
  640.             }
  641.         else
  642.             return (TRUE);
  643.       }
  644.       
  645.     quit();
  646.     return (FALSE);
  647. }
  648.  
  649. /*
  650.  *    HandleMenuCommand - preform a command denoted by the arguments.
  651.  *        mResult - the result of the menu event
  652.  *        modifiers- modifiers from the menu event
  653.  */
  654.  
  655. void HandleMenuCommand( long mResult, short modifiers)
  656. {
  657.     register short i;
  658.     short theItem, theMenu;
  659.  
  660.     theMenu = mResult >> 16;
  661.     theItem = mResult & 0xffff;
  662.     switch(theMenu) {
  663.     case appleMenu:
  664.         if (theItem==1)                /* About Dialog */
  665.             applAbout();
  666.         else
  667.           {
  668.             Str255
  669.                 name;
  670.             GetItem(myMenus[0], theItem, name);        /* Desk accessory */
  671.             OpenDeskAcc(name);
  672.           }
  673.         break;
  674.  
  675.     case fileMenu:
  676.     case NfileMenu:
  677.         switch(theItem) {            
  678.             
  679.         case FLopen:
  680.             PresentOpenConnectionDialog();                    /* Open a connection */                
  681.             break;
  682.  
  683.         case FLclose:
  684. //            if ( TelInfo->numwindows<1 ) break;                /* Close a connection */
  685.             CloseAWindow(FrontWindow());
  686. #if 0
  687.             if ( screens[scrn].active == CNXN_ISCORPSE) {
  688.                 netclose( screens[scrn].port);
  689.                 destroyport( scrn);
  690.                 }
  691.             else {
  692.                 if ( !ReallyClose( scrn) ) break;
  693.                 netclose(screens[scrn].port);
  694.                 removeport( scrn);
  695.                 }
  696.             if (TelInfo->numwindows <1) 
  697.                 {
  698.                 DisableItem( myMenus[Conn],0);
  699.                 DisableItem(myMenus[Conn],COnext);
  700.                 DrawMenuBar();
  701.                 }
  702. #endif
  703.             break;
  704.  
  705.         case FLload:                                /* Load a set */
  706.             LoadSet();
  707.             break;
  708.         case FLsave:                                /* Save a set */
  709.             if (TelInfo->numwindows<1) break;
  710.             SaveSet();
  711.             break;
  712.         case FLbin:                                    /* Toggle MacBinary on/off */
  713.             TelInfo->MacBinary = !TelInfo->MacBinary;
  714.             if (TelInfo->MacBinary) {
  715.                 CheckItem(myMenus[Fil], FLbin,TRUE);
  716.                 }
  717.             else {
  718.                 CheckItem(myMenus[Fil], FLbin,FALSE);
  719.                 }
  720.             break;
  721.  
  722.         case FLlog:                                        /* Toggle FTP window on/off*/
  723.             TelInfo->ftplogon=!TelInfo->ftplogon;
  724.             if(TelInfo->ftplogon) {
  725.                 CheckItem(myMenus[Fil],FLlog,TRUE);
  726.                 RSshow(ftplog->vs);
  727.                 SelectWindow(ftplog->wind);
  728.                 }
  729.             else {
  730.                 CheckItem(myMenus[Fil],FLlog,FALSE);
  731.                 RShide(ftplog->vs);
  732.                 }
  733.             break;
  734.  
  735.         case FLprint:                                /* Print Selection (or gr) */
  736.             PrintSelection();
  737.             break;
  738.  
  739.         case FLpset:                                    /* Set up for printer */
  740.             PrintPageSetup();
  741.             break;
  742.  
  743.         case FLquit:
  744.             (void) HandleQuit();
  745.             break;
  746.  
  747.         }
  748.         break;
  749.  
  750.     case editMenu:
  751.     case NeditMenu:
  752.         if (!SystemEdit(theItem-1)) {                /* Is this mine? */
  753.             switch(theItem) {
  754.             case EDcopy:                            /* Copy */
  755.                 i = MacRGfindwind(FrontWindow());    /* is ICR window? */
  756.                 if (i >= 0)
  757.                     MacRGcopy(FrontWindow());        /* copy the ICR window */
  758.                 else {
  759.                     i=RGgetdnum(FrontWindow());
  760.                     if (i>-1)                        /* Copy Graphics */
  761.                         copyGraph( i);
  762.                     else                            /* Copy Text */
  763.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  764.                             copyText( i);
  765.                 }
  766.                 break;
  767.  
  768.             case EDcopyt:                            /* Copy Table */
  769.                 /* 
  770.                 *  tech note #180 trick to get MultiFinder to pay attention 
  771.                 */
  772.                 if (!SystemEdit(EDcopy-1)) {        /* tell it we did a copy */
  773.                     i=RGgetdnum(FrontWindow());
  774.                     if (i>-1)            /* Copy Graphics */
  775.                         copyGraph( i);
  776.                     else                /* Copy Text */
  777.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  778.                             copyTable( i);
  779.                 }
  780.                 break;
  781.  
  782.             case EDpaste:                            /* Paste */
  783.                 if (TelInfo->numwindows<1)
  784.                         break;
  785.                     else paste();            /* Paste if there is a wind to do to*/
  786.                 break;
  787.             case EDmacros:                            /* Set them Macros */
  788.                 Macros();
  789.                 break;
  790.             default:
  791.                 break;
  792.             }
  793.         }
  794.         break;
  795.  
  796.     case connMenu:
  797.     case NconnMenu:
  798.         if (theItem == COnext) {
  799.             short    scratchshort;
  800.             if (TelInfo->numwindows >1) {
  801.                 scratchshort = WindowPtr2ScreenIndex(FrontWindow()) + 1;
  802.                 // Skip over inactive connections
  803.                 while(    (screens[scratchshort].active != CNXN_ACTIVE) &&
  804.                         (screens[scratchshort].active != CNXN_ISCORPSE) &&
  805.                         (scratchshort <= TelInfo->numwindows+1))                        
  806.                     scratchshort++;
  807.                     
  808.                 if ((scratchshort < 0) || (scratchshort >= TelInfo->numwindows))
  809.                     scratchshort = 0;
  810.                 SelectWindow(screens[scratchshort].wind);
  811.                 }
  812.             break;
  813.             }
  814.         
  815.         if (theItem == COtitle)    {
  816.             ChangeWindowName(FrontWindow());
  817.             break;
  818.             }
  819.             
  820.         if (theItem >= FIRST_CNXN_ITEM) {
  821.             if ((theItem - FIRST_CNXN_ITEM-1)>(TelInfo->numwindows+1)) break;  /* rotten danish */
  822.             if (screens[theItem - FIRST_CNXN_ITEM].active != CNXN_ACTIVE) {
  823.                 displayStatus(theItem - FIRST_CNXN_ITEM);    /* Tell them about it..... */
  824.                 break;
  825.                 }
  826.             else {
  827.                 HiliteWindow(screens[scrn].wind, FALSE);
  828.                 changeport(scrn,(theItem - FIRST_CNXN_ITEM));
  829.                 if (!(modifiers &  optionKey)) SelectWindow(screens[scrn].wind);
  830.                 else HiliteWindow(screens[scrn].wind, TRUE);
  831.                 }
  832.             }
  833.         break;
  834.  
  835.     case netMenu:
  836.     case NnetMenu:
  837.         switch(theItem) {
  838.         case NEftp:                                        /* Send FTP command */
  839.         case NEip:                                        /* Send IP Number */
  840.             if (TelInfo->numwindows<1) break;
  841.             {    char tmpout[30];                        /* Basically the same except for */
  842.                 unsigned char tmp[4];                    /* The ftp -n phrase in NEftp */
  843.  
  844.                 if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  845.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  846.                                 screens[scrn].kblen);/* if not empty send buffer */
  847.                     screens[scrn].kblen=0;
  848.                     }
  849.                 netgetip(tmp);
  850.                 if (theItem == NEftp) {
  851.                     if ((gFTPServerPrefs->ServerState == 1) && !(modifiers & shiftKey))
  852.                         sprintf(tmpout,"ftp -n %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  853.                     else
  854.                         sprintf(tmpout,"ftp %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  855.                     }
  856.                 else
  857.                     sprintf(tmpout,"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  858.                 netwrite(screens[scrn].port,tmpout,strlen(tmpout));
  859.                 if (screens[scrn].echo)
  860.                     VSwrite(screens[scrn].vs,tmpout, strlen(tmpout));
  861.             }
  862.             break;
  863.  
  864.         case NEayt:                                /* Send "Are You There?"*/
  865.             if (TelInfo->numwindows<1) break;
  866.             netpush(screens[scrn].port);
  867.             netwrite(screens[scrn].port, "\377\366",2);
  868.             break;
  869.  
  870.         case NEao:                                /* Send "Abort Output"*/
  871.             if (TelInfo->numwindows<1) break;
  872.             netpush(screens[scrn].port);
  873.             netwrite(screens[scrn].port, "\377\365",2);
  874.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  875.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  876.             break;
  877.  
  878.         case NEinter:                                /* Send "Interrupt Process"*/
  879.             if (TelInfo->numwindows<1) break;
  880.             netpush(screens[scrn].port);
  881.             netwrite(screens[scrn].port, "\377\364",2);
  882.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  883.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  884.             break;
  885.  
  886.         case NEec:                                /* Send "Erase Character"*/
  887.             if (TelInfo->numwindows<1) break;
  888.             netpush(screens[scrn].port);
  889.             netwrite(screens[scrn].port, "\377\367",2);
  890.             break;
  891.  
  892.         case NEel:                                /* Send "Erase Line"*/
  893.             if (TelInfo->numwindows<1) break;
  894.             netpush(screens[scrn].port);
  895.             netwrite(screens[scrn].port, "\377\370",2);
  896.             break;
  897.             
  898.         case NEscroll:                            /* Suspend Network */
  899.             TelInfo->ScrlLock=!TelInfo->ScrlLock;
  900.             if (TelInfo->ScrlLock) 
  901.                 CheckItem(myMenus[Net], NEscroll,TRUE);
  902.             else 
  903.                 CheckItem(myMenus[Net], NEscroll,FALSE);
  904.             break;
  905.  
  906.         case NEnet:                                /* Show Network Numbers */
  907.             showNetNumbers();
  908.             break;
  909.  
  910.         default:
  911.             break;
  912.         }
  913.         break;
  914.  
  915.     case termMenu:
  916.     case NtermMenu:
  917.         switch(theItem) {
  918.  
  919.         case EMbs:                                /* Backspace for backspace  */
  920.             if (TelInfo->numwindows<1) break;
  921.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  922.             screens[scrn].bsdel=0;
  923.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  924.             break;
  925.         
  926.         case EMdel:                                /* Delete for backspace */
  927.             if (TelInfo->numwindows<1) break;
  928.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  929.             screens[scrn].bsdel=1;
  930.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  931.             break;
  932.  
  933.         case EMecho:                                /* Toggle Local Echo (if poss.) */
  934.             if (TelInfo->numwindows < 1) break;
  935.             if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  936.                 netwrite( screens[scrn].port, screens[scrn].kbbuf,
  937.                             screens[scrn].kblen);    /* if not empty send buffer */
  938.                 screens[scrn].kblen=0;
  939.                 }
  940.             screens[scrn].echo= !screens[scrn].echo;    /* toggle */
  941.             if (screens[scrn].echo) {                    /* LOCAL ECHO */
  942.                 netwrite(screens[scrn].port,"\377\376\001",3);
  943.                 CheckItem(myMenus[Emul],EMecho,TRUE);
  944.                 }
  945.             else {                                        /* REMOTE ECHO */
  946.                 netwrite(screens[scrn].port,"\377\375\001",3);
  947.                 CheckItem(myMenus[Emul],EMecho,FALSE);
  948.                 }
  949.             break;
  950.             
  951.         case EMwrap:                                /* wrap mode */
  952.             if (TelInfo->numwindows < 1) break;
  953.             if (!screens[scrn].wrap) {                /* is off, turn on */
  954.                 screens[scrn].wrap = 1;
  955.                 CheckItem( myMenus[Emul],EMwrap, TRUE);
  956.                 VSwrite(screens[scrn].vs, "\033[?7h",5);    /* kick emulator */
  957.                 }
  958.             else {
  959.                 screens[scrn].wrap = 0;
  960.                 CheckItem( myMenus[Emul],EMwrap, FALSE);
  961.                 VSwrite(screens[scrn].vs, "\033[?7l",5);
  962.                 }
  963.             break;
  964.         
  965.         case EMarrowmap:                                        /* JMB */
  966.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  967.             screens[scrn].arrowmap = !screens[scrn].arrowmap;    /* JMB */
  968.             if (screens[scrn].arrowmap)                            /* JMB */
  969.                 CheckItem( myMenus[Emul], EMarrowmap, TRUE);    /* JMB */
  970.             else                                                /* JMB */
  971.                 CheckItem( myMenus[Emul], EMarrowmap, FALSE);    /* JMB */
  972.             break;                                                /* JMB */
  973.             
  974.         case EMpgupdwn:
  975.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  976.             screens[scrn].pgupdwn = !screens[scrn].pgupdwn;        /* JMB */
  977.             if (screens[scrn].pgupdwn)                            /* JMB */
  978.                 CheckItem( myMenus[Emul], EMpgupdwn, TRUE);        /* JMB */
  979.             else                                                /* JMB */
  980.                 CheckItem( myMenus[Emul], EMpgupdwn, FALSE);    /* JMB */
  981.             break;                                                /* JMB */
  982.             
  983.         case EMscroll:                                        /* Scrollback on CLS */
  984.             if (TelInfo->numwindows<1) break;
  985.             screens[scrn].ESscroll = !screens[scrn].ESscroll;
  986.             VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  987.             if (screens[scrn].ESscroll)
  988.                 CheckItem(myMenus[Emul],EMscroll, TRUE);
  989.             else
  990.                 CheckItem(myMenus[Emul],EMscroll, FALSE);
  991.             break;
  992.             
  993.         case EMpage:                                    /* TEK page command */
  994.             if (TelInfo->numwindows<1) break;
  995.             parse( &screens[scrn],  (unsigned char *) "\033\014",2);    /* BYU LSC */
  996.             break;
  997.  
  998.         case EMclear:                                /* BYU 2.4.8 - Clear on TEK page */
  999.             if (TelInfo->numwindows<1) break;
  1000.             screens[scrn].tekclear = !screens[scrn].tekclear;
  1001.             if (screens[scrn].tekclear)
  1002.                 CheckItem(myMenus[Emul],EMclear, TRUE);
  1003.             else
  1004.                 CheckItem(myMenus[Emul],EMclear, FALSE);
  1005.             break;
  1006.  
  1007.         case EMscreensize:
  1008.             if (TelInfo->numwindows<1) break;        /* NCSA: SB */
  1009.             SetScreenDimensions((short)scrn);        /* NCSA: SB */
  1010.             break;
  1011.  
  1012.         case EMreset:                                    /* Reset Screen */
  1013.             if (TelInfo->numwindows<1) break;
  1014.             VSreset(screens[scrn].vs);                    /* Reset it */
  1015.             screens[scrn].timing=0;
  1016.             screens[scrn].wrap = 0;                        /* turns wrap off */
  1017.             CheckItem( myMenus[Emul],EMwrap, FALSE);
  1018.             break;
  1019.         case EMjump:                                    /* Jump Scroll */
  1020.             if (TelInfo->numwindows<1) break;
  1021.             FlushNetwork(scrn);                            /* Flush it */
  1022.             break;
  1023.             
  1024.         case EMsetup:                            /* need dialog to enter new key values */
  1025.             setupkeys();
  1026.             break;
  1027.  
  1028.         case EMcolor:                                        /* Set color */
  1029.             if (TelInfo->numwindows<1) break;
  1030.             if (theWorld.hasColorQD)
  1031.                 RScprompt(screens[scrn].vs);    /* Color it */
  1032.             break;
  1033.  
  1034.         case EMcapture:                                            /* BYU 2.4.18 - Capture session to file */
  1035.             if (VSiscapturing(screens[scrn].vs)) {                /* BYU 2.4.18 */
  1036.                 CloseCaptureFile(screens[scrn].vs);                /* BYU 2.4.18 */
  1037.             } else {                                            /* BYU 2.4.18 */
  1038.                 if(VSopencapture(scrn, screens[scrn].vs))        /* BYU 2.4.18 */
  1039.                     CheckItem(myMenus[Emul], EMcapture,TRUE);    /* BYU 2.4.18 */
  1040.             }                                                    /* BYU 2.4.18 */
  1041.  
  1042.             break;                                                /* BYU 2.4.18 */
  1043.  
  1044.         default:
  1045.             break;
  1046.         }
  1047.         break;
  1048.     case fontMenu:
  1049.         if (TelInfo->numwindows>0) {
  1050.             short     itemFontNum;
  1051.             Str255     temp;
  1052.     
  1053.             GetItem( myMenus[Font], theItem, temp);
  1054.             GetFNum( temp, &itemFontNum);
  1055.  
  1056.             RSchangefont( screens[scrn].vs, itemFontNum, 0, 1);
  1057.             CheckFonts();
  1058.             }
  1059.         break;
  1060.     case sizeMenu:
  1061.         if (TelInfo->numwindows>0) {
  1062.             long    itemFontSize;
  1063.             Str255     temp;
  1064.             
  1065.             GetItem( myMenus[Sizem], theItem, temp);    /* JMB 2.6 -- Much safer to do it */
  1066.             StringToNum(temp, &itemFontSize);        /*                this way! */
  1067.  
  1068.             RSchangefont( screens[scrn].vs, -1, itemFontSize, 1);
  1069.             CheckFonts();
  1070.             }
  1071.         break;
  1072.     case opspecMenu:                                            // JMB
  1073.         OpenPortSpecial(myMenus[OpSpec], theItem);                // JMB
  1074.         break;                                                    // JMB
  1075.     case prefsMenu:
  1076.         switch(theItem) {
  1077.             case prfGlobal:
  1078.                 Cenviron();
  1079.                 break;
  1080.             case prfFTP:
  1081.                 Cftp();
  1082.                 break;
  1083.             case prfSess:
  1084.                 EditConfigType(SESSIONPREFS_RESTYPE, &EditSession);
  1085.                 CheckOpSpecSubmenu();
  1086.                 break;
  1087.             case prfTerm:
  1088.                 EditConfigType(TERMINALPREFS_RESTYPE, &EditTerminal);
  1089.                 break;
  1090.             case prfFTPUser:
  1091.                 EditConfigType(FTPUSER, &EditFTPUser);
  1092.             }
  1093.         break;
  1094.     case transMenu:
  1095.         if (TelInfo->numwindows>0) {
  1096.             CheckNational(theItem-1);        // Set up the menu
  1097.             transBuffer(screens[scrn].national, theItem-1);    // Translate the scrollback buffer
  1098.             // and redraw the screen
  1099.             VSredraw(screens[scrn].vs,0,0,VSmaxwidth(screens[scrn].vs),VSgetlines(screens[scrn].vs)-1);    /* LU */
  1100.             screens[scrn].national = theItem-1;
  1101.             }
  1102.         break;
  1103.     default:
  1104.         break;
  1105.     
  1106.     }
  1107.     HiliteMenu(0);
  1108.   } /* HandleMenuCommand */
  1109.  
  1110. //    Take the user's new translation choice and make sure the proper tables exist to do 
  1111. //        the translations.  If there is a problem, return the default translation as the chouce.
  1112. void    CheckNational(short choice)
  1113. {
  1114.     short i;
  1115.             
  1116.     for(i=1; i<=(nNational+1);i++)
  1117.         if ((choice+1) == i)                    /* Check the Current NatLang */
  1118.             CheckItem( myMenus[National], i, TRUE);
  1119.         else
  1120.             CheckItem( myMenus[National], i, FALSE);
  1121.  
  1122. }
  1123.  
  1124. /*
  1125.  *    extractmenu - remove a connection from the menu.
  1126.  */
  1127.  
  1128. void extractmenu(short screen)
  1129. {
  1130.     DelMenuItem(myMenus[Conn], screen + FIRST_CNXN_ITEM);
  1131.     AdjustMenus();
  1132. }
  1133.  
  1134. /*
  1135.  *    addinmenu - add a connection's name to the menu in position pnum. (name is
  1136.  *        an str255 pointed at by temps).
  1137.  */
  1138.  
  1139. void addinmenu( short screen, Str255 temps, char mark)
  1140. {
  1141.     InsMenuItem(myMenus[Conn], "\pDoh", (screen-1) + FIRST_CNXN_ITEM);
  1142.     SetItem(myMenus[Conn], screen + FIRST_CNXN_ITEM, temps);        // Avoid metas
  1143.     SetItemMark( myMenus[Conn], screen + FIRST_CNXN_ITEM, mark);
  1144.     AdjustMenus();
  1145. }
  1146.  
  1147. /*    Set the item mark for <scrn> to opening connection */
  1148. void SetMenuMarkToOpeningForAGivenScreen( short scrn)
  1149. {
  1150.     unsigned char c=0xa5;
  1151.  
  1152.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, c );
  1153. }
  1154.  
  1155. /*    Set the item mark for <scrn> to opened connection */
  1156. void SetMenuMarkToLiveForAGivenScreen( short scrn)
  1157. {
  1158.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, noMark);
  1159.     AdjustMenus();
  1160. }
  1161.  
  1162. void DoTheMenuChecks(void)
  1163. {
  1164.     short    active;
  1165.     short    windownum;
  1166.  
  1167.     if (TelInfo->numwindows>0)
  1168.         {
  1169.         EnableItem( myMenus[Conn],0);
  1170.         DrawMenuBar();
  1171.         }
  1172.  
  1173.     else 
  1174.         {
  1175.         DisableItem(myMenus[Conn],0);
  1176.         DrawMenuBar();
  1177.         }
  1178.  
  1179.     active =0;
  1180.     
  1181.     for (windownum=0;windownum<TelInfo->numwindows;windownum++)
  1182.         if (screens[windownum].active == CNXN_ACTIVE) active++;
  1183.         
  1184.     if (active<2)    
  1185.         DisableItem(myMenus[Conn],COnext);
  1186.     else EnableItem(myMenus[Conn],COnext);
  1187.  
  1188.     if (!active)
  1189.         {
  1190. /*        DisableItem(myMenus[Edit],EDcopy);
  1191.         DisableItem(myMenus[Edit],EDcopyt); */
  1192.         DisableItem(myMenus[Edit],EDpaste);
  1193.         DisableItem(myMenus[Emul],0);
  1194.         DrawMenuBar();
  1195.         }
  1196.     else 
  1197.         {
  1198. /*        EnableItem(myMenus[Edit],EDcopy);
  1199.         EnableItem(myMenus[Edit],EDcopyt); */
  1200.         EnableItem(myMenus[Edit],EDpaste);
  1201.         EnableItem( myMenus[Emul],0);
  1202.         DrawMenuBar();
  1203.         }
  1204. }
  1205.  
  1206.  
  1207.  
  1208. /*--------------------------------------------------------------------------*/
  1209. /* SetupMenusForSelection                                                    */
  1210. /* If there is a selection on screen, then let the user copy and print.        */
  1211. /* If not, then, oh well....just disable the menus and forget about it        */
  1212. /* ...and to think that this good stuff USED to be in rsmac.c.                 */
  1213. /* This is called from RSselect after the user clicks in the window, and     */
  1214. /* was moved here for modularity    - SMB                                    */
  1215. /*--------------------------------------------------------------------------*/
  1216. void SetMenusForSelection (short selected)                    /* NCSA: SB */    
  1217. {                                                            /* NCSA: SB */
  1218.     if (!selected)                                            /* NCSA: SB */
  1219.         {                                                    /* NCSA: SB */
  1220.         DisableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1221.         DisableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1222.         DisableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1223.         }                                                    /* NCSA: SB */
  1224.     else                                                     /* NCSA: SB */
  1225.         {                                                    /* NCSA: SB */
  1226.         EnableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1227.         EnableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1228.         EnableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1229.         }                                                    /* NCSA: SB */
  1230. }                                                            /* NCSA: SB */
  1231.  
  1232.  
  1233. /*----------------------------------------------------------------------*/
  1234. /* NCSA: SB - SetColumnWidth                                            */
  1235. /*    Allow the user to FINALLY pick how many columns he wants on the     */
  1236. /*    screen.  Set up a dialog box to pick the # of columns, and then        */
  1237. /*    size-up the Telnet screen accordingly.  NOTE: The user still needs    */
  1238. /*     to do a "resize", unless he is using NAWS                            */
  1239. /*----------------------------------------------------------------------*/
  1240. void SetScreenDimensions(short scrn)
  1241. {
  1242.     DialogPtr    dtemp;
  1243.     Str255        ColumnsSTR, LinesSTR;
  1244.     long        columns, lines;
  1245.     short        ditem, notgood;
  1246.     
  1247.     dtemp=GetNewMyDialog( SizeDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1248.     
  1249.     SetCursor(theCursors[normcurs]);
  1250.  
  1251.     notgood = 1;
  1252.     lines = VSgetlines(screens[scrn].vs);
  1253.     columns = VSgetcols(screens[scrn].vs) + 1;
  1254.     
  1255.     while (notgood) {
  1256.         notgood = 0;                                /* Default to good */
  1257.         NumToString(columns, ColumnsSTR);
  1258.         NumToString(lines, LinesSTR);
  1259.         SetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1260.         SetTEText(dtemp, LinesNumber, LinesSTR);
  1261.         SelIText( dtemp, ColumnsNumber, 0, 32767);
  1262.     
  1263.         ditem = 3;
  1264.         while(ditem>2)
  1265.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1266.     
  1267.         if (ditem == DLOGCancel) {
  1268.             DisposeDialog( dtemp);
  1269.             return;
  1270.             }
  1271.         
  1272.         GetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1273.         StringToNum(ColumnsSTR, &columns);
  1274.         GetTEText(dtemp, LinesNumber, LinesSTR);
  1275.         StringToNum(LinesSTR, &lines);
  1276.         
  1277.         if (columns < 10) {
  1278.             columns = 10;
  1279.             notgood = 1;
  1280.             }
  1281.         else if (columns > 132) {
  1282.             columns = 132;
  1283.             notgood = 1;
  1284.             }
  1285.  
  1286.         if (lines < 10) {
  1287.             lines = 10;
  1288.             notgood = 1;
  1289.             }
  1290.         else if (lines > 200) {
  1291.             lines = 200;
  1292.             notgood = 1;
  1293.             }
  1294.         
  1295.         if (notgood) SysBeep(4);
  1296.     }
  1297.     
  1298.     DisposeDialog( dtemp);
  1299.     
  1300.     VSsetlines( screens[scrn].vs, lines);
  1301.     RScalcwsize( screens[scrn].vs, columns);
  1302. /*    RSsize( screens[scrn].wind, NULL, 0); */
  1303.  
  1304.     if (screens[scrn].naws)
  1305.         SendNAWSinfo(&screens[scrn], (short)columns, (short)lines);
  1306.         
  1307.     updateCursor(1);
  1308. }
  1309.  
  1310. void    ChangeWindowName(WindowPtr    theWindow)
  1311. {
  1312.     DialogPtr    dptr;
  1313.     short        itemHit;
  1314.     Str255        theName;
  1315.  
  1316.     if( theWindow != NULL) {
  1317.         InitCursor();
  1318.         dptr = GetNewMySmallDialog(WinTitlDLOG, NULL, kInFront, (void *)ThirdCenterDialog );
  1319.  
  1320.         GetWTitle(theWindow, theName); 
  1321.         SetTEText( dptr, kWinNameTE, theName);
  1322.         SelIText( dptr, kWinNameTE, 0, 250 );
  1323.  
  1324.         itemHit = 0;
  1325.         while(itemHit != DLOGOk && itemHit != DLOGCancel)
  1326.             ModalDialog(DLOGwOK_CancelUPP, &itemHit);
  1327.         
  1328.         if(itemHit == DLOGOk) {
  1329.             GetTEText(dptr, kWinNameTE, theName);
  1330.             set_new_window_name(theName, theWindow);
  1331.             }
  1332.             
  1333.         DisposDialog(dptr);
  1334.         }
  1335. }
  1336.  
  1337. void    set_new_window_name(Str255 theName, WindowPtr theWindow)
  1338. {
  1339.     short    i;
  1340.     
  1341.     if(theName[0]) {
  1342.         i = WindowPtr2ScreenIndex(theWindow);
  1343.         if (i >= 0) {
  1344.             i += FIRST_CNXN_ITEM;
  1345.             SetWTitle(theWindow, theName);
  1346.             SetItem(myMenus[Conn], i, theName);
  1347.             }
  1348.         }
  1349. }
  1350.